#pragma once
#include "UdpLocalSocket.h"

#define ELABORATE_THREADS 6
#define TEST_PERIOD_TIME 60000

struct _dns_udp_query_message
{
    DNS_MESSAGE_BUFFER m_stMessageBufferPrefix;
    BYTE    m_baMessageTail[512 - sizeof(DNS_MESSAGE_BUFFER)];
};

// CMainWorkerThread
class CDnsMessageWB;
class CDnsResorceRecord;
class CIp4ElaborateThread;
class CMainWorkerThread : public CWinThread
{
	DECLARE_DYNCREATE(CMainWorkerThread)

public:
	CMainWorkerThread();
	virtual ~CMainWorkerThread();

public:
	virtual BOOL InitInstance();
	virtual int ExitInstance();

protected:
	DECLARE_MESSAGE_MAP()
public:
    CList<CIp4ElaborateThread*,CIp4ElaborateThread*> m_oElaboratedThreadsList;
    CList<CIp4ElaborateThread*,CIp4ElaborateThread*> m_oAllocatedThreadsList;
    virtual BOOL OnIdle(LONG lCount);
    int m_nRetCode;
    HANDLE m_hWfpEngineHandle;
    FWP_BYTE_BLOB* m_pDnsServerAppID;
    UINT64 m_nStreamFilterID;
    UINT64 m_nDatagramDataFilterID;
    CMutex m_oDnsSessionsListLock;
    UINT32 m_nStreamCalloutId;
    UINT32 m_nDatagramsCalloutId;
    UINT32 m_nAleFlowEstablishedCalloutId;
    UINT32 m_nAleFlowEstablishedV6CalloutId;
    UINT64 m_nAleFlowEstablishedFilterID;
    bool m_bOnDelete;
    CSemaphore m_oThreadsSemaphore;
    HANDLE m_hDnsFilterDevice;
    CUdpLocalSocket m_oUdpLocalSocket;
    CEvent m_oDnsResponceEvent;
    SOCKADDR m_stLocalDnsServerAddress;
    bool m_bServiceTest;
    WORD m_wXid;
    _dns_udp_query_message m_stUdpDNSQueryMessage;
    BYTE m_baUdpBuffer[512];
    UINT32 m_nStreamV6CalloutId;
    UINT32 m_nDatagramsV6CalloutId;
    UINT64 m_nAleFlowEstablishedV6FilterID;
    UINT64 m_nStreamV6FilterID;
    UINT64 m_nDatagramV6DataFilterID;
//    virtual BOOL PreTranslateMessage(MSG* pMsg);
//    virtual BOOL ProcessMessageFilter(int code, LPMSG lpMsg);
    UINT64 m_nFilterWeight;
};
